package org.tio.sitexxx.im.server.handler;

import org.tio.core.ChannelContext;
import org.tio.sitexxx.im.common.Command;
import org.tio.sitexxx.im.common.CommandHandler;
import org.tio.sitexxx.im.common.ImPacket;
import org.tio.sitexxx.im.common.bs.DemoNtf;
import org.tio.sitexxx.im.common.bs.DemoReq;
import org.tio.sitexxx.im.server.Ims;
import org.tio.utils.json.Json;

/**
 * @author tanyaowu 
 */
@CommandHandler(Command.DEMO_REQ)
public class DemoReqHandler implements ImServerHandler {
	@Override
	public void handler(ImPacket packet, ChannelContext channelContext, boolean isWebsocket) throws Exception {
		DemoReq demoReq = Json.toBean(packet.getBodyStr(), DemoReq.class);

		System.out.println(Json.toJson(demoReq));

		DemoNtf demoNtf = new DemoNtf();
		demoNtf.setMsg("收到你发的消息:" + demoReq.getText());

		ImPacket imPacket = new ImPacket(Command.DEMO_NTY, demoNtf);
		Ims.sendToAll(imPacket); //发给所有用户
	}
}
